package com.pet.admin.interceptor;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class SignInInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {

        HttpSession session = httpServletRequest.getSession();
        if(!StringUtils.isEmpty(session.getAttribute("adminEmail"))){
            return true;
        } else{
            httpServletResponse.sendRedirect(httpServletRequest.getContextPath()+"/index");
            return false;
        }

    }
}
